# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=readline
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_basever=6.3
_patchlevel=008
pkgver=${_basever}.${_patchlevel}
pkgrel=1
pkgdesc="MinGW port of readline for editing typed command lines (mingw-w64)"
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         #"${MINGW_PACKAGE_PREFIX}-ncurses"
         #"${MINGW_PACKAGE_PREFIX}-pdcurses"
         "${MINGW_PACKAGE_PREFIX}-termcap")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
license=('GPL')
url="https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html"
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${_basever}.tar.gz"{,.sig}
        readline-6.3-mingw.patch)
if [ $_patchlevel -gt 00 ]; then
    for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
        source=(${source[@]} https://ftp.gnu.org/gnu/${_realname}/${_realname}-$_basever-patches/readline${_basever//./}-$(printf "%03d" $p){,.sig})
    done
fi

sha256sums=('56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43'
            'SKIP'
            '54793953160cc40175fedb4bd73121703e1c88d692f85366386929a32665b6f7'
            '1a79bbb6eaee750e0d6f7f3d059b30a45fc54e8e388a8e05e9c3ae598590146f'
            'SKIP'
            '39e304c7a526888f9e112e733848215736fb7b9d540729b9e31f3347b7a1e0a5'
            'SKIP'
            'ec41bdd8b00fd884e847708513df41d51b1243cecb680189e31b7173d01ca52f'
            'SKIP'
            '4547b906fb2570866c21887807de5dee19838a60a1afb66385b272155e4355cc'
            'SKIP'
            '877788f9228d1a9907a4bcfe3d6dd0439c08d728949458b41208d9bf9060274b'
            'SKIP'
            '5c237ab3c6c97c23cf52b2a118adc265b7fb411b57c93a5f7c221d50fafbe556'
            'SKIP'
            '4d79b5a2adec3c2e8114cbd3d63c1771f7c6cf64035368624903d257014f5bea'
            'SKIP'
            '3bc093cf526ceac23eb80256b0ec87fa1735540d659742107b6284d635c43787'
            'SKIP')

prepare() {
  cd "${srcdir}/readline-${_basever}"

  for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
    msg "applying patch readline${_basever//./}-$(printf "%03d" $p)"
    patch -Np0 -i ${srcdir}/readline${_basever//./}-$(printf "%03d" $p)
  done

  patch -Np1 -i ${srcdir}/readline-6.3-mingw.patch
  # Remove RPATH from shared objects (FS#14366)
  sed -i 's|-Wl,-rpath,$(libdir) ||g' support/shobj-conf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${_basever}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-shared \
    --without-curses
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make install DESTDIR="${pkgdir}"
}
